<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/12
 * Time: 10:13
 */

namespace App\admin\TableView;


use App\admin\TableView\BaseClass\BaseViewList;
use App\Jobs\Fun;
use App\Models\Admin\ApilistModel;
use App\Models\Admin\CategoryModel;
use App\Models\Admin\CompanyModel;
use App\Models\Admin\OrderBaleModel;
use App\Models\Admin\UserModel;
use App\Models\AreaModel;
use App\Models\Main\AdModel;
use App\Services\Admin\OrderBaleService;
use Faker\Provider\Company;

class OrderBaleListView extends BaseViewList
{

    public function get_model()
    {

        return new OrderBaleModel();
    }

    public $show_add = false; ///显示添加按钮
    /**
     * 是否显示删除按钮
     */
    public $show_delete = true;
    public $topTitle = '货单列表';
    public $PageSize = 10;

    public $breadcrumb = '<li><a href="/mcadmin">Home</a></li>
        <li><a href="javascript:;">货单列表</a></li>
        ';

    public $html = '';


    //  public $show_add = false; ///显示添加按钮

    /**
     * 获取表格的唯一名字
     */
    public function getName()
    {
        return 'OrderBaleModel';
    }


    /**
     * 需要继承,然后定义每行需要显示的数据格式
     */
    public function Labels()
    {
        return array(
            //   BaseViewList::Button_checkbox=>[],
            'id' => 50,
            'paixu' => 40,
            'name' => 50,
            'cate' => 150,
            'img' => 150,
            'bond' => 150,
            'status' => 150,
            'period' => 150,
            'created_at' => 150,
            'count' =>50,
            BaseViewList::Button_control => [
                BaseViewList::Button_Edit,
                 BaseViewList::Button_Delete
            ]
        );
    }

    /**
     * 对话框中的各个字段
     */
    public function dialog()
    {
        return array(

            array(
                'zd' => 'paixu',
                'type' => self::dialog_number
            ),
        );
    }

    /**
     * 方便继承,多一层过滤
     */
    public function ModelTohtml($key, $model)
    {
        if($key==='created_at'||$key==='period'){
            return Fun::date($model->$key);
        }
        if($key=='img'){
            return $this->toImg($model->$key);
        }
        if($key=='cate'){
            return  CategoryModel::getName($model->$key);
        }
        if($key=='status'){
            return  OrderBaleModel::getStatus($model->$key);
        }
        if($key=='count'){
            return '<a class="count" target="_blank" href="/mcadmin/huodan/temp?id='.$model->id.'">'.OrderBaleModel::getCount($model->id).'</a>';
        }

        return parent::ModelTohtml($key, $model);
    }

    /**
     * 返回查询的条件
     */
    public function find()
    {
        $find = $this->get_model()->where([
        ]);
        $name=$_GET['name']??'';
        if($name!==''){
            $find->whereRaw("name LIKE ?",["%".$name."%"]);
        }
        $cate=$_GET['cate']??'';
        if($cate!==''){
            $find->where([
                "cate"=>$cate
            ]);
        }

        $uid=$_GET['uid']??'';
        if($uid!==''){
            $find->where([
                "uid"=>$uid
            ]);
        }

        $find->orderBy('id', 'DESC');
        $find->orderBy('paixu', 'DESC');
        return $find;
    }


    /**
     * 顶部的选择区,参数,如果为空,则不显示选择器
     */
    public function getselectAttr()
    {
        $orderService=new OrderBaleService();
        $catelist=$orderService->getCateList();
        $list=[
            ''=>'所有'
        ];
        foreach ($catelist as $ke=>$vo){
            $list[$vo['id']]=$vo['name'];
        }
      //  print_r($catelist);exit;

        /// self::dropDownList,
        $where = [
            'name' =>
                [
                    'title' => '货单名字',
                    'inputtype' => self::htmlText
                ],
            'cate' =>
                [
                    'title' => '货单名字',
                   'inputtype'=>BaseViewList::dropDownList,
          'items'=>$list ,
          'default'=>''
                ]
        ];
        return $where;
    }

}
